﻿using System;
using System.Linq;
using System.Collections.Generic;

namespace ConsoleApp2
{
	class Data
	{
		public string TimeTo { get; set; }
		public string TimeFrom { get; set; }
		public string ApplyNo { get; set; }
		public DateTime QueueTime { get; set; }
	}
	class Program
	{
		static public List<string> Get()
		{
			var now = DateTime.Now;
			var begin = new DateTime(now.Year, now.Month, now.Day);
			var end = begin.AddDays(1);
			now = begin.AddHours(9).AddMinutes(30);
			//过号
			int count = 3;
			Data[] data = new Data[]{
			new Data{TimeFrom="08:00",TimeTo="09:00",ApplyNo="202101",QueueTime=begin.AddHours(8).AddMinutes(3) },
			new Data{TimeFrom="08:00",TimeTo="09:00",ApplyNo="202102",QueueTime=begin.AddHours(8).AddMinutes(6) },
			new Data{TimeFrom="08:00",TimeTo="09:00",ApplyNo="202103",QueueTime=begin.AddHours(8).AddMinutes(10) },
			new Data{TimeFrom="08:00",TimeTo="09:00",ApplyNo="202104",QueueTime=begin.AddHours(8).AddMinutes(15) },
			new Data{TimeFrom="08:00",TimeTo="09:00",ApplyNo="202105",QueueTime=begin.AddHours(8).AddMinutes(27) },

			new Data{TimeFrom="09:00",TimeTo="10:00",ApplyNo="202110",QueueTime=begin.AddHours(9).AddMinutes(5) },
			new Data{TimeFrom="09:00",TimeTo="10:00",ApplyNo="202111",QueueTime=begin.AddHours(9).AddMinutes(20) },
			new Data{TimeFrom="09:00",TimeTo="10:00",ApplyNo="2021A11",QueueTime=begin.AddHours(9).AddMinutes(21) },
			new Data{TimeFrom="09:00",TimeTo="10:00",ApplyNo="2021A12",QueueTime=begin.AddHours(9).AddMinutes(22) },

			new Data{TimeFrom="10:00",TimeTo="11:00",ApplyNo="202112",QueueTime=begin.AddHours(9).AddMinutes(5) },
			new Data{TimeFrom="10:00",TimeTo="11:00",ApplyNo="202113",QueueTime=begin.AddHours(9).AddMinutes(10) },

			new Data{TimeFrom="08:00",TimeTo="09:00",ApplyNo="202114",QueueTime=begin.AddHours(9).AddMinutes(15) },
			new Data{TimeFrom="08:00",TimeTo="09:00",ApplyNo="202115",QueueTime=begin.AddHours(9).AddMinutes(16) },
			new Data{TimeFrom="08:00",TimeTo="09:00",ApplyNo="202116",QueueTime=begin.AddHours(9).AddMinutes(20) },
			new Data{TimeFrom="08:00",TimeTo="09:00",ApplyNo="202117",QueueTime=begin.AddHours(9).AddMinutes(21) },
			};
			List<Data> finish, beforeAmount, late, afterAmount, early;
			finish = new List<Data>();
			beforeAmount = new List<Data>();
			early = new List<Data>();
			var nowTime = now.ToString("HH:mm");
			foreach (var item in data)
			{
				if (string.Compare(item.TimeTo, nowTime) < 0)
					finish.Add(item);
				else if (string.Compare(item.TimeFrom, nowTime) < 0 && string.Compare(item.TimeTo, nowTime) > 0)
					beforeAmount.Add(item);
				else if (string.Compare(item.TimeFrom, nowTime) > 0)
					early.Add(item);
			}
			afterAmount = beforeAmount.Skip(count).ToList();
			beforeAmount = beforeAmount.Take(count).ToList();
			late = finish.Where(appo => string.Compare(appo.QueueTime.ToString("HH:mm"), appo.TimeTo) > 0).ToList();
			finish.RemoveRange(finish.Count - late.Count, late.Count);
			return finish.Select(a => a.ApplyNo).Concat(beforeAmount.Select(a => a.ApplyNo))
			.Concat(late.Select(a => a.ApplyNo)).Concat(afterAmount.Select(a => a.ApplyNo))
			.Concat(early.Select(a => a.ApplyNo)).ToList();
		}
		static void Main1(string[] args)
		{
			Console.WriteLine(string.Join(',', Get()));
            Console.ReadKey();
		}
	}
}
